package cn.wolfcode.rocketmq._02_model;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception{
        //1 创建一个生产者对象, 并且指定一个生产者组
        DefaultMQProducer producer = new DefaultMQProducer("producer-model");
        //发送消息的超时时间
        producer.setSendMsgTimeout(10000);
        //2 设置名字服务的地址
        producer.setNamesrvAddr("localhost:9876");
        //3 启动生产者
        producer.start();
        //4 创建一个消息,把要发送信息放在消息对象中
        Message message = new Message("02-model", "tagAA", "秃头罗罗".getBytes("utf-8"));
        //5 发送消息
        //producer.send(message);
        SendResult send = producer.send(message);
        System.out.println(send.getMsgId());
        //6 关闭连接
        producer.shutdown();
    }
}
